{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import math\n",
    "import numpy as np\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "headers = [\"buying\", \"maint\", \"doors\", \"persons\",\"lug_boot\", \"safety\", \"class\"]\n",
    "data = pd.read_csv(\"carData.csv\", header=None, names=headers)\n",
    "\n",
    "data = data.sample(frac=1).reset_index(drop=True) # shuffle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "for h in headers:\n",
    "    data[h] = data[h].astype('category')\n",
    "    data[h] = data[h].cat.codes\n",
    "\n",
    "data.set_index(\"class\", inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "size = len(data)\n",
    "train_size = int(math.floor(size * 0.7))\n",
    "train_data = data[:train_size]\n",
    "test_data = data[train_size:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='entropy', max_depth=None,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d_tree = DecisionTreeClassifier(criterion=\"entropy\")\n",
    "d_tree.fit(train_data, train_data.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Score with criterion = entropy: 0.9691714836223507\n"
     ]
    }
   ],
   "source": [
    "d_tree.predict(test_data.iloc[:, 0:6])\n",
    "score = d_tree.score(test_data, test_data.index)\n",
    "\n",
    "print('Score with criterion = entropy: {0}'.format(score))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,\n",
       "            max_features=None, max_leaf_nodes=None,\n",
       "            min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "            min_samples_leaf=1, min_samples_split=2,\n",
       "            min_weight_fraction_leaf=0.0, presort=False, random_state=None,\n",
       "            splitter='best')"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d_tree = DecisionTreeClassifier(criterion=\"gini\")\n",
    "d_tree.fit(train_data, train_data.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Score with criterion = gini: 0.9653179190751445\n"
     ]
    }
   ],
   "source": [
    "d_tree.predict(test_data.iloc[:, 0:6])\n",
    "score = d_tree.score(test_data, test_data.index)\n",
    "\n",
    "print('Score with criterion = gini: {0}'.format(score))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl4lPW5//H3nY2ELQESdgiyLy4IYbEuoKCiVq3axa1u\nVdu61O5q67G/ix6rPS6151RbreK+/JT6a61iESJo9SgSRFFJ2LewZCEkLCH7/ftjRo0BmQQyeSbM\n53VdXMw888zMndHMh+f7fL/3Y+6OiIjIgSQEXYCIiMQ+hYWIiESksBARkYgUFi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4FPgYws0vN7P3w4w99FiJmdpqZvWtmH5jZi+FeYJjZXWa23MyWmdk9wf1YIl9Ni/JEWijc\nGfgVdz/SzKYCrwJHuvs6MxsF/BdwvrvXmtmDwHvAHEJ9jM5w9z1mdjPQAfgT8C4w0t3dzDLUglxi\nkdp9iBy69919Xfj2NGA8sDjUuog0Qk3dJgOjgXfC21MIhcROoAp4xMxeBeL+yoASmxQWIoduT6Pb\nBjzh7rc23sHMzgbmuftFTZ9sZhMJhcyFwA3AKVGsVeSg6JyFSMvtArp8xWO5wDfNrCd8fm3kbEJD\nUceb2dDw9o5mNjx83iI93DTyx8DY6Jcv0nI6shBpIXffbmbvmNknwF6gqNFjy83sNuB1M0sAaoHr\n3f09M7sCeM7MOoR3v41Q8PzDzFIJHZX8pC1/FpHm0gluERGJSMNQIiISkcJCREQiUliIiEhECgsR\nEYlIYSEiIhEpLEREJCKFhYiIRKSwEBGRiP4/GY0oPWh5vaEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f431fbed0b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.ensemble import RandomForestClassifier\n",
    "\n",
    "def randomForestScores(limitTrees, train_data):\n",
    "    scores = []\n",
    "    for i in range(1, limitTrees):\n",
    "        toFitTrainData = train_data\n",
    "        d_tree = RandomForestClassifier(n_estimators=i, criterion='entropy')\n",
    "        d_tree.fit(toFitTrainData, toFitTrainData.index)\n",
    "        \n",
    "        d_tree.predict(test_data.iloc[:, 0:6])\n",
    "        score = d_tree.score(test_data, test_data.index)\n",
    "        scores.append(score)\n",
    "    return scores\n",
    "\n",
    "scores = randomForestScores(11, train_data) # teste de 1 a 10 árvores\n",
    "\n",
    "plt.plot(range(1, 11), scores)\n",
    "plt.xlabel('trees')\n",
    "plt.ylabel('score')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
